// Project name:JavaRedis
// Creator:muhong
// Date time:2022/12/11,12:36 下午
// Name:ChannelHandlerAdapter

package org.gmh.channel;

import org.gmh.channel.handler.ChannelHandlerContext;

public abstract class ChannelHandlerAdapter implements ChannelHandler {

    boolean added;

    protected void ensureNotSharable(){
        if (isSharable()){
            throw new IllegalStateException("ChannelHandler "+getClass().getName()+" is not allow to be shared");
        }
    }

    public boolean isSharable(){
        Class<?> clazz = getClass();
        return clazz.isAnnotationPresent(Sharable.class);
    }

    @Override
    public void handlerAdd(ChannelHandlerContext ctx) throws Exception {

    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.fireExceptionCaught(cause);
    }
}
